<div class="page-container" v-cloak>
    <el-card>
        <template #header>
            <div class="breadcrumb" style=" overflow: hidden;">
                <el-breadcrumb separator="/" style=" float: left;  ">
                    <el-breadcrumb-item><a href="{:url('admin/room/index')}">包厢列表</a></el-breadcrumb-item>
                </el-breadcrumb>
                <el-breadcrumb separator="/" style=" float: right;  ">
                    <el-button type="primary" @click="refresh()">刷新</el-button>
                </el-breadcrumb>
            </div>
        </template>
        <div>
            <el-form :inline="true">
                <el-form-item>
                    <el-input v-model="where.room_name" placeholder="名称"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-select filterable v-model="where.store_id" placeholder="所属门店">
                        <el-option label="不限" :value="0"></el-option>
                        <el-option v-for="(item,index) in store_list" :value="index"
                                   :label="item"></el-option>
                    </el-select>
                </el-form-item>

                <el-form-item>
                    <el-link>
                        <el-button type="primary" @click="searchEvent">查询</el-button>
                    </el-link>
                    <el-link href="{:url('admin/room/edit')}">
                        <el-button type="primary">新增</el-button>
                    </el-link>
                </el-form-item>
            </el-form>
        </div>
        <div>
            <el-table

                    :data="data_list"
                    style="width: 100%">
                <el-table-column
                        prop="room_id"
                        label="ID"
                        min-width="80">
                </el-table-column>
                <el-table-column
                        prop="door_id"
                        label="门禁编码"
                        min-width="180">
                </el-table-column>
                <el-table-column
                        prop="name"
                        label="包厢名称"
                        min-width="180">
                </el-table-column>
                <el-table-column label="图片">
                    <template v-slot:default="scope">
                        <img :src="scope.row.image_url" style="width: 50px;">
                    </template>
                </el-table-column>
                <el-table-column label="门禁版本">
                    <template v-slot:default="scope">
                        <!-- 使用 scope.row 来访问当前行的数据 -->
                        <span v-if="scope.row.door_type === 2" style="color: #bb8a24">版本3</span>
                        <span v-if="scope.row.door_type === 1" style="color: #529b2e">版本2</span>
                        <span v-else>版本1</span>
                    </template>
                </el-table-column>

                <el-table-column label="包厢状态" min-width="80">
                    <template v-slot:default="scope">
                        <!-- 使用 scope.row 来访问当前行的数据 -->
                        <span v-if="scope.row.status === 1" style="color: #529b2e">显示</span>
                        <span v-else>隐藏</span>
                    </template>
                </el-table-column>
                <el-table-column
                        prop="store_name"
                        label="店铺名称"
                        min-width="100">
                </el-table-column>
                <el-table-column
                        prop="sort"
                        label="排序"
                        min-width="50">
                </el-table-column>
                <el-table-column
                        align="center"
                        min-width="180"
                        label="操作">
                    <template #default="{row}">
                        <el-link :href="'{:url('admin/room/edit')}?room_id='+row.room_id">
                            <el-button type="primary">编辑</el-button>
                        </el-link>
                        <el-link>
                            <el-button type="success" @click="open(row.door_id,row.door_type)">开门</el-button>
                        </el-link>
                        <el-link>
                            <el-button type="danger" @click="close(row.door_id,row.door_type)">断电</el-button>
                        </el-link>
                        <!--                        <el-link>-->
                        <!--                            <el-button @click="deleteEvent(row)" type="danger">删除</el-button>-->
                        <!--                        </el-link>-->
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        background
                        layout="prev, pager, next"
                        :total="total_num"
                        :current-page="current_page"
                        :page-size="per_page"
                        @current-change="currentChangeEvent"
                >
                </el-pagination>
            </div>
        </div>
    </el-card>
</div>

<script>
    const App = {
        data() {
            return {
                is_init_list: true,
                role_list: [],
                store_list: [],
                where: {},
            }
        },
        methods: {
            GetList() {
                this.httpGet("{:url('admin/room/index/lists')}", {
                    page: this.current_page,
                    ...this.where
                }).then(res => {
                    let {lists = {}, role_list = [], store_list = []} = res.data
                    this.role_list = role_list
                    this.store_list = store_list
                    this.handRes(lists)
                })
            },
            deleteEvent({room_id}) {
                this.$confirm('是否确认删除该管理员？', '提示').then(() => {
                    this.httpDelete("{:url('admin/room/delete')}/" + room_id, {}).then(res => {
                        if (res.status) {
                            this.$message.success(res.msg)
                            this.GetList()
                        }
                    })
                }).catch(err => {
                })
            },
            searchEvent() {
                this.GetList()
            },

            open(door_id, door_type) {
                this.httpPost("{:url('admin/room/open')}/" + door_id + "/" + door_type, {}).then(res => {
                    if (res.status) {
                        this.$message.success(res.msg)
                    }
                })
            },
            close(door_id, door_type) {
                this.httpPost("{:url('admin/room/close')}/" + door_id + "/" + door_type, {}).then(res => {
                    if (res.status) {
                        this.$message.success(res.msg)
                    }
                })
            },
        }
    }
</script>